import { get } from '@packages/lib-request';
import Modal from '@packages/lib-modal';
import os from '@packages/lib-os';
import { showPage } from '@packages/lib-router';
import { handleApi } from '@packages/lib-api';

import S from './index.m.less';

const API = handleApi({
    check: '/v1.0/livesale/get-user-extend-info-l',
});

function checkAddr() {
    return new Promise((resolve) => {
        get(API.check, (res) => {
            resolve(res);
        });
    });
}

// 检查是否有待填写地址的订单
export default async function checkEmptyAddr(redirect = false) {
    if (os.wpt) {
        return true;
    }
    const res = await checkAddr();
    const jump = redirect ? WPT.redirect : showPage;
    if (res.code == 0 && res.data.saleUri) {
        Modal.infoTip('您有笔已支付订单未填写收货地址', {
            btnList: [
                {
                    btnName: '取消',
                    className: S.cancelBtn,
                },
                {
                    btnName: '前往填写',
                    callback: () => {
                        jump(`/my/orderdetail/${res.data.saleUri}`);
                    },
                },
            ],
            simpleText: true,
        });
        return false;
    }
    return true;
}
